package demo4j.apijson;

import apijson.RequestMethod;
import apijson.orm.AbstractSQLConfig;
import apijson.orm.Join;
import apijson.orm.SQLConfig;
import com.alibaba.fastjson.JSONObject;

import java.util.List;

public class APIJSONSQLConfig extends AbstractSQLConfig<Long> {
    public APIJSONSQLConfig() {
        super(RequestMethod.GET);
    }

    @Override
    public String getDBVersion() {
        return "8.0.11";
    }

    @Override
    public String getDBUri() {
        return "jdbc:mysql://localhost:3306?userSSL=false&serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8";
    }

    @Override
    public String getDBAccount() {
        return "root";
    }

    @Override
    public String getDBPassword() {
        return "123456";
    }

    public static AbstractSQLConfig.Callback<Long> SIMPLE_CALLBACK;

    static {
        SIMPLE_CALLBACK = new AbstractSQLConfig.SimpleCallback<>() {
            @Override
            public SQLConfig<Long> getSQLConfig(RequestMethod method, String database, String schema, String datasource, String table) {
                SQLConfig<Long> config = new APIJSONSQLConfig();
                config.setMethod(method);
                config.setDatabase(database);
                config.setDatasource(datasource);
                config.setSchema(schema);
                config.setTable(table);
                return config;
            }
        };

        TABLE_KEY_MAP.put("User", "apijson_user");
        TABLE_KEY_MAP.put("Privacy", "apijson_privacy");
    }

    public static SQLConfig<Long> newSQLConfig(RequestMethod method, String table, String alias, JSONObject request, List<Join> joinList, boolean isProcedure) throws Exception {
        return AbstractSQLConfig.newSQLConfig(method, table, alias, request, joinList, isProcedure, SIMPLE_CALLBACK);
    }
}
